home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / g__~1 / gplibo17.zoo / g++-include / streambu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-13  |  18.6 KB  |  575 lines

  1. //    This is part of the iostream library, providing -*- C++ -*- input/output.
  2. //    Copyright (C) 1991 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15.  
  16.  
  17. #ifndef _STREAMBUF_H
  18. #define _STREAMBUF_H
  19. #ifdef __GNUG__
  20. #pragma interface
  21. #endif
  22.  
  23. /* #define _G_IO_THROW */ /* Not implemented:  ios::failure */
  24.  
  25. #include <g_config.h>
  26. #ifdef _G_NEED_STDARG_H
  27. #include <stdarg.h>
  28. #endif
  29. #ifndef fpos_t
  30. #define fpos_t _G_fpos_t
  31. #endif
  32.  
  33. #ifndef atarist
  34. #ifndef EOF
  35. #define EOF (-1)
  36. #endif
  37. #ifndef NULL
  38. #define NULL ((void*)0)
  39. #endif
  40. #else
  41. #include <stddef.h>
  42. #include <stdio.h>
  43. extern "C" unsigned long __DEFAULT_BUFSIZ__;
  44. #endif
  45.  
  46. class ostream; class streambuf; class backupbuf;
  47.  
  48. // In case some header files defines these as macros.
  49. #undef open
  50. #undef close
  51.  
  52. #ifdef _G_FRIEND_BUG
  53. extern int __UNDERFLOW(streambuf*);
  54. extern int __OVERFLOW(streambuf*, int);
  55. #endif
  56. extern "C" int __underflow(streambuf*);
  57. extern "C" int __overflow(streambuf*, int);
  58.  
  59. typedef _G_off_t streamoff;
  60. typedef _G_off_t streampos; // Should perhaps be _G_fpos_t ?
  61.  
  62. typedef unsigned long __fmtflags;
  63. typedef unsigned char __iostate;
  64.  
  65. struct _ios_fields { // The data members of an ios.
  66.     streambuf *_strbuf;
  67.     ostream* _tie;
  68.     int _width;
  69.     __fmtflags _flags;
  70.     _G_wchar_t _fill;
  71.     __iostate _state;
  72.     __iostate _exceptions;
  73.     int _precision;
  74. };
  75.  
  76. #define _IOS_GOOD    0
  77. #define _IOS_EOF    1
  78. #define _IOS_FAIL    2
  79. #define _IOS_BAD    4
  80.  
  81. #define _IOS_INPUT    1
  82. #define _IOS_OUTPUT    2
  83. #define _IOS_ATEND    4
  84. #define _IOS_APPEND    8
  85. #define _IOS_TRUNC    16
  86. #define _IOS_NOCREATE    32
  87. #define _IOS_NOREPLACE    64
  88. #define _IOS_BIN    128
  89. #ifdef atarist
  90.   /* force text mode */
  91. #define _IOS_TEXT    256
  92. #endif
  93.  
  94. #ifdef _STREAM_COMPAT
  95. enum state_value {
  96.     _good = _IOS_GOOD,
  97.     _eof = _IOS_EOF,
  98.     _fail = _IOS_FAIL,
  99.     _bad = _IOS_BAD };
  100. enum open_mode {
  101.     input = _IOS_INPUT,
  102.     output = _IOS_OUTPUT,
  103.     atend = _IOS_ATEND,
  104.     append = _IOS_APPEND
  105. #ifdef atarist
  106.     ,
  107.     in_bin =_IOS_INPUT|_IOS_BIN,  // force bin mode regardless of default mode
  108.     out_bin=_IOS_OUTPUT|_IOS_BIN,
  109.     app_bin=_IOS_APPEND|_IOS_BIN,
  110.     binary = _IOS_BIN,              // flag that may be or'ed in
  111.  
  112.     in_text=_IOS_INPUT|_IOS_TEXT,    // force text mode
  113.     out_text=_IOS_OUTPUT|_IOS_TEXT,
  114.     app_text=_IOS_APPEND|_IOS_TEXT,
  115.     text=_IOS_TEXT                // flag that may be or'ed in
  116. #endif
  117.  };
  118. #endif
  119.  
  120. class ios : public _ios_fields {
  121.   public:
  122.     typedef __fmtflags fmtflags;
  123.     typedef int iostate;
  124.     typedef int openmode;
  125.     enum io_state {
  126.     goodbit = _IOS_GOOD,
  127.     eofbit = _IOS_EOF,
  128.     failbit = _IOS_FAIL,
  129.     badbit = _IOS_BAD };
  130.     enum open_mode {
  131.     in = _IOS_INPUT,
  132.     out = _IOS_OUTPUT,
  133.     ate = _IOS_ATEND,
  134.     app = _IOS_APPEND,
  135.     trunc = _IOS_TRUNC,
  136.     nocreate = _IOS_NOCREATE,
  137.     noreplace = _IOS_NOREPLACE,
  138.     bin = _IOS_BIN
  139. #ifdef atarist
  140.     ,
  141.     in_bin = _IOS_INPUT|_IOS_BIN,
  142.     out_bin = _IOS_OUTPUT|_IOS_BIN,
  143.         ate_bin = _IOS_ATEND|_IOS_BIN,
  144.     app_bin = _IOS_APPEND|_IOS_BIN,
  145.         binary = _IOS_BIN,
  146.  
  147.     in_text = _IOS_INPUT|_IOS_TEXT,
  148.     out_text = _IOS_OUTPUT|_IOS_TEXT,
  149.         ate_text = _IOS_ATEND |_IOS_TEXT,
  150.     app_text = _IOS_APPEND|_IOS_TEXT,
  151.         text = _IOS_TEXT
  152. #endif
  153.  };
  154.     enum seek_dir { beg, cur, end};
  155.     // ANSI: typedef enum seek_dir seekdir; etc
  156.     enum { skipws=01, left=02, right=04, internal=010,
  157.        dec=020, oct=040, hex=0100,
  158.        showbase=0200, showpoint=0400, uppercase=01000, showpos=02000,
  159.        scientific=04000, fixed=010000, unitbuf=020000, stdio=040000,
  160.        dont_close=0x80000000 //Don't delete streambuf on stream destruction
  161.        };
  162.     enum { // Masks.
  163.     basefield=dec+oct+hex,
  164.     floatfield = scientific+fixed,
  165.     adjustfield = left+right+internal
  166.     };
  167.  
  168. #ifdef _G_IO_THROW
  169.     class failure : public xmsg {
  170.     ios* _stream;
  171.       public:
  172.     failure(ios* stream) { _stream = stream; }
  173.     failure(string cause, ios* stream) { _stream = stream; }
  174.     ios* rdios() const { return _stream; }
  175.     };
  176. #endif
  177.  
  178.     ostream* tie() const { return _tie; }
  179.     ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; }
  180.  
  181.     // Methods to change the format state.
  182.     _G_wchar_t fill() const { return (_G_wchar_t)_fill; }
  183.     _G_wchar_t fill(_G_wchar_t newf)
  184.     {_G_wchar_t oldf = (_G_wchar_t)_fill; _fill = (char)newf; return oldf;}
  185.     fmtflags flags() const { return _flags; }
  186.     fmtflags flags(fmtflags new_val) {
  187.     fmtflags old_val = _flags; _flags = new_val; return old_val; }
  188.     int precision() const { return _precision; }
  189.     int precision(int newp) {
  190.     unsigned short oldp = _precision; _precision = (unsigned short)newp;
  191.     return oldp; }
  192.     fmtflags setf(fmtflags val) {
  193.     fmtflags oldbits = _flags;
  194.     _flags |= val; return oldbits; }
  195.     fmtflags setf(fmtflags val, fmtflags mask) {
  196.     fmtflags oldbits = _flags;
  197.     _flags = (_flags & ~mask) | (val & mask); return oldbits; }
  198.     fmtflags unsetf(fmtflags mask) {
  199.     fmtflags oldbits = _flags & mask;
  200.     _flags &= ~mask; return oldbits; }
  201.     int width() const { return _width; }
  202.     int width(int val) { int save = _width; _width = val; return save; }
  203.  
  204. #ifdef _G_IO_THROW
  205.     void _throw_failure() { throw new ios::failure(this); }
  206. #else
  207.     void _throw_failure() { }
  208. #endif
  209.  
  210.     streambuf* rdbuf() const { return _strbuf; }
  211.     void clear(iostate state = 0) {
  212.     _state = _strbuf ? state : state|badbit;
  213.     if (_state & _exceptions) _throw_failure(); }
  214.     void set(iostate flag) { _state |= flag;
  215.     if (_state & _exceptions) _throw_failure(); }
  216.     int good() const { return _state == 0; }
  217.     int eof() const { return _state & ios::eofbit; }
  218.     int fail() const { return _state & (ios::badbit|ios::failbit); }
  219.     int bad() const { return _state & ios::badbit; }
  220.     iostate rdstate() const { return _state; }
  221.     operator void*() const { return fail() ? (void*)0 : (void*)(-1); }
  222.     int operator!() const { return fail(); }
  223.     iostate exception(iostate enable) {
  224.     iostate old = _exceptions; _exceptions = enable;
  225.     if (_state & _exceptions) _throw_failure();
  226.     return old; }
  227.  
  228.     static int sync_with_stdio(int on);
  229.     static void sync_with_stdio() { sync_with_stdio(1); }
  230.  
  231. #ifdef _STREAM_COMPAT
  232.     void unset(state_value flag) { _state &= ~flag; }
  233.     void close();
  234.     int is_open();
  235.     int readable();
  236.     int writable();
  237. #endif
  238.  
  239.   protected:
  240.     ios(streambuf* sb = 0, ostream* tie = 0);
  241.     virtual ~ios();
  242.     void init(streambuf* sb) { _state=0; _strbuf=sb; }
  243. };
  244.  
  245. #if __GNUG__==1
  246. typedef int _seek_dir;
  247. #else
  248. typedef ios::seek_dir _seek_dir;
  249. #endif
  250.  
  251. // Magic numbers and bits for the _flags field.
  252. // The magic numbers use the high-order bits of _flags;
  253. // the remaining bits are abailable for variable flags.
  254. // Note: The magic numbers must all be negative if stdio
  255. // emulation is desired.
  256.  
  257. #define _IO_MAGIC 0xFBAD0000 /* Magic number */
  258. #define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
  259. #define _IO_MAGIC_MASK 0xFFFF0000
  260. #define _S_USER_BUF 1 /* User owns buffer; don't delete it on close. */
  261. #define _S_UNBUFFERED 2
  262. #define _S_NO_READS 4 /* Reading not allowed */
  263. #define _S_NO_WRITES 8 /* Writing not allowd */
  264. #define _S_EOF_SEEN 0x10
  265. #define _S_ERR_SEEN 0x20
  266. #define _S_DELETE_DONT_CLOSE 0x40
  267. #define _S_LINKED 0x80 // Set if linked (using _chain) to streambuf::_list_all.
  268. #define _S_IN_BACKUP 0x100
  269. #define _S_LINE_BUF 0x200
  270. #define _S_TIED_PUT_GET 0x400 // Set if put and get pointer logicly tied.
  271. #define _S_CURRENTLY_PUTTING 0x800
  272. #define _S_IS_APPENDING 0x1000
  273. #define _S_IS_BACKUPBUF 0x4000
  274. #define _S_IS_FILEBUF 0x8000
  275. #ifdef atarist
  276. #define _S_IS_BINARY 0x2000    // phew!! 
  277. #endif
  278.  
  279. // A streammarker remembers a position in a buffer.
  280. // You are guaranteed to be able to seek back to it if it is saving().
  281. class streammarker {
  282.     friend class streambuf;
  283. #ifdef _G_FRIEND_BUG
  284.     friend int __UNDERFLOW(streambuf*);
  285. #else
  286.     friend int __underflow(streambuf*);
  287. #endif
  288.     struct streammarker *_next;  // Only if saving()
  289.     streambuf *_sbuf; // Only valid if saving().
  290.     streampos _spos; // -2: means that _pos is valid.
  291.     void set_streampos(streampos sp) { _spos = sp; }
  292.     void set_offset(long offset) { _pos = offset; _spos = (streampos)(-2); }
  293.     // If _pos >= 0, it points to _buf->Gbase()+_pos.
  294.     // if _pos < 0, it points to _buf->eBptr()+_pos.
  295.     long _pos;
  296.   public:
  297.     streammarker(streambuf *sb);
  298.     ~streammarker();
  299.     int saving() { return  _spos == -2; }
  300.     int delta(streammarker&);
  301.     int delta();
  302. };
  303.  
  304. struct __streambuf {
  305.     // NOTE: If this is changed, also change __FILE in stdio/stdio.h!
  306.     unsigned long _flags; /* High-order word is _IO_MAGIC; rest is flags. */
  307.     char* _gptr;    /* Current get pointer */
  308.     char* _egptr;    /* End of get area. */
  309.     char* _eback;    /* Start of putback+get area. */
  310.     char* _pbase;    /* Start of put area. */
  311.     char* _pptr;    /* Current put pointer. */
  312.     char* _epptr;    /* End of put area. */
  313.     char* _base;    /* Start of reserve area. */
  314.     char* _ebuf;    /* End of reserve area. */
  315.     struct streambuf *_chain;
  316.  
  317.     // The following fields are used to support backing up and undo.
  318.     friend class streammarker;
  319.     char *_other_gbase; // Pointer to start of non-current get area.
  320.     char *_aux_limit;  // Pointer to first valid character of backup area,
  321.     char *_other_egptr; // Pointer to end of non-current get area.
  322.     streammarker *_markers;
  323.  
  324. #define __HAVE_COLUMN /* temporary */
  325.     // 1+column number of pbase(); 0 is unknown.
  326.     unsigned short _cur_column;
  327.     char _unused;
  328.     char _shortbuf[1];
  329. };
  330.  
  331. extern unsigned __adjust_column(unsigned start, const char *line, int count);
  332.  
  333. struct streambuf : private __streambuf {
  334.     friend class ios;
  335.     friend class istream;
  336.     friend class ostream;
  337.     friend class streammarker;
  338. #ifdef _G_FRIEND_BUG
  339.     friend int __UNDERFLOW(streambuf*);
  340. #else
  341.     friend int __underflow(streambuf*);
  342. #endif
  343.   protected:
  344.     static streambuf* _list_all; /* List of open streambufs. */
  345.     streambuf*& xchain() { return _chain; }
  346.     void _un_link();
  347.     void _link_in();
  348.     char* gptr() const { return _gptr; }
  349.     char* pptr() const { return _pptr; }
  350.     char* egptr() const { return _egptr; }
  351.     char* epptr() const { return _epptr; }
  352.     char* pbase() const { return _pbase; }
  353.     char* eback() const { return _eback; }
  354.     char* base() const { return _base; }
  355.     char* ebuf() const { return _ebuf; }
  356.     long blen() const { return _ebuf - _base; }
  357.     void xput_char(char c) { *_pptr++ = c; }
  358. #ifdef atarist
  359.     int  is_binary() { return ((_flags & _S_IS_BINARY) ? 1 : 0); }
  360.     void set_binary() { _flags |= _S_IS_BINARY; }
  361. #endif
  362.     unsigned long xflags() { return _flags; }
  363.     unsigned long xflags(unsigned long f) { unsigned long int fl = _flags; _flags = f; return fl; }
  364.     void xsetflags(unsigned long f) { _flags |= f; }
  365.     void xsetflags(unsigned long f, unsigned long mask) { _flags = (_flags & ~mask) | (f & mask); }
  366.     void gbump(_G_size_t n) { _gptr += n; }
  367.     void pbump(_G_size_t n) { _pptr += n; }
  368.     void setb(char* b, char* eb, int a=0);
  369.     void setp(char* p, char* ep) { _pbase=_pptr=p; _epptr=ep; }
  370.     void setg(char* eb, char* g, char *eg) { _eback=eb; _gptr=g; _egptr=eg; }
  371.     char *shortbuf() { return _shortbuf; }
  372.  
  373.     int in_backup() { return _flags & _S_IN_BACKUP; }
  374.     // The start of the main get area:  FIXME:  wrong for write-mode filebuf?
  375.     char *Gbase() { return in_backup() ? _other_gbase : _eback; }
  376.     // The end of the main get area:
  377.     char *eGptr() { return in_backup() ? _other_egptr : _egptr; }
  378.     // The start of the backup area:
  379.     char *Bbase() { return in_backup() ? _eback : _other_gbase; }
  380.     char *Bptr() { return _aux_limit; }
  381.     // The end of the backup area:
  382.     char *eBptr() { return in_backup() ? _egptr : _other_egptr; }
  383.     char *Nbase() { return _other_gbase; }
  384.     char *eNptr() { return _other_egptr; }
  385.     int have_backup() { return _other_gbase != NULL; }
  386.     int have_markers() { return _markers != NULL; }
  387.     long _least_marker();
  388.     void switch_to_main_get_area();
  389.     void switch_to_backup_area();
  390.     void free_backup_area();
  391.     void unsave_markers(); // Make all streammarkers !saving().
  392.     int put_mode() { return _flags & _S_CURRENTLY_PUTTING; }
  393.     int switch_to_get_mode();
  394.     
  395.     streambuf(unsigned long flags=0);
  396.   public:
  397.     static int flush_all();
  398.     static void flush_all_linebuffered(); // Flush all line buffered files.
  399.     virtual int underflow() = 0; // Leave public for now
  400.     virtual int overflow(int c = EOF) = 0; // Leave public for now
  401.     virtual int doallocate();
  402.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  403.     virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
  404.     int seekmark(streammarker& mark, long delta = 0);
  405.     int sputbackc(char c);
  406.     int sungetc();
  407.     virtual ~streambuf();
  408.     int unbuffered() { return _flags & _S_UNBUFFERED ? 1 : 0; }
  409.     int linebuffered() { return _flags & _S_LINE_BUF ? 1 : 0; }
  410.     void unbuffered(int i)
  411.     { if (i) _flags |= _S_UNBUFFERED; else _flags &= ~_S_UNBUFFERED; }
  412.     void linebuffered(int i)
  413.     { if (i) _flags |= _S_LINE_BUF; else _flags &= ~_S_LINE_BUF; }
  414.     int allocate() { // For AT&T compatibility
  415.     if (base() || unbuffered()) return 0;
  416.     else return doallocate(); }
  417.     // Allocate a buffer if needed; use _shortbuf if appropriate.
  418.     void allocbuf() { if (base() == NULL) doallocbuf(); }
  419.     void doallocbuf();
  420.     virtual int sync();
  421.     virtual int pbackfail(int c);
  422.     virtual streambuf* setbuf(char* p, _G_size_t len);
  423.     long in_avail() { return _egptr - _gptr; }
  424.     long out_waiting() { return _pptr - _pbase; }
  425.     virtual _G_size_t xsputn(const char* s, _G_size_t n);
  426.     _G_size_t sputn(const char* s, _G_size_t n) { return xsputn(s, n); }
  427.     int padn(char pad, _G_size_t n); // Emit 'n' copies of 'pad'.
  428.     virtual _G_size_t xsgetn(char* s, _G_size_t n);
  429.     _G_size_t sgetn(char* s, _G_size_t n) { return xsgetn(s, n); }
  430.     _G_size_t ignore(_G_size_t);
  431.     virtual int get_column();
  432.     virtual int set_column(int);
  433.     long sgetline(char* buf, _G_size_t n, char delim, int putback_delim);
  434.     int sbumpc() {
  435.     if (_gptr >= _egptr && __underflow(this) == EOF) return EOF;
  436. #if 1 /* ndef atarist */
  437.     else return *(unsigned char*)_gptr++;
  438. #else
  439.         {
  440.         int ch = *(unsigned char*)_gptr++;
  441.         if((!is_binary()) && (ch == '\r'))
  442.         return sbumpc();
  443.         return ch;
  444.     }
  445. #endif
  446.  }
  447.     int sgetc() {
  448.     if (_gptr >= _egptr && __underflow(this) == EOF) return EOF;
  449. #if 1 /* ndef atarist */
  450.         return *(unsigned char*)_gptr;
  451. #else
  452.         {
  453.         int ch = *(unsigned char *)_gptr;
  454.         if((!is_binary()) && (ch == '\r'))
  455.         return snextc();
  456.         return ch;
  457.     }
  458. #endif    
  459.     }
  460.     int snextc() {
  461.     if (_gptr >= _egptr && __underflow(this) == EOF) return EOF;
  462.     return _gptr++, sgetc(); }
  463. #if 0 /* def atarist -- not needed anymore because of stdibuf that uses
  464.      stdio to do writes with fwrite where text/bin mode are taken care of
  465.        */
  466.     int _atari_putc(int c) {
  467.     if ((!is_binary()) && ((c == '\n') || (c == '\r')))
  468.     {
  469.         if(c == '\r')
  470.         return (int)c;
  471.         if (_pptr >= _epptr)
  472.         {
  473.         if(__overflow(this, (unsigned char)'\r') == EOF) return EOF;
  474.         }
  475.         else
  476.         *_pptr++ = '\r';
  477.     }
  478.     if (_pptr >= _epptr) return __overflow(this, (unsigned char)c);
  479.     return *_pptr++ = c, (unsigned char)c;
  480.     }
  481. #endif
  482.     int sputc(int c) {
  483. #if 1 /* ndef atarist */
  484.     if (_pptr >= _epptr) return __overflow(this, (unsigned char)c);
  485.     return *_pptr++ = c, (unsigned char)c;
  486. #else
  487.     return _atari_putc(c);
  488. #endif    
  489.     }
  490.  
  491.     void stossc() { if (_gptr < _egptr) _gptr++; }
  492.     int vscan(char const *fmt0, _G_va_list ap, ios* stream = NULL);
  493.     int scan(char const *fmt0 ...);
  494.     int vform(char const *fmt0, _G_va_list ap);
  495.     int form(char const *fmt0 ...);
  496. #if 0 /* Work in progress */
  497.     int collumn();  // Current collumn number (of put pointer). -1 is unknown.
  498.     void collumn(int c);  // Set collumn number of put pointer to c.
  499. #endif
  500. };
  501.  
  502. // A backupbuf is a streambuf with full backup and savepoints on reading.
  503. // All standard streambufs in the GNU iostream library are backupbufs.
  504.  
  505. // A backupbuf may have two get area:
  506. // - The main get area, and (sometimes) the putback area.
  507. // Whichever one of these contains the gptr is the current get area;
  508. // the other one is the non-current get area.
  509.  
  510. class backupbuf : public streambuf {
  511.     friend class streammarker;
  512.   protected:
  513.     backupbuf(int flags=0) : streambuf(flags|_S_IS_BACKUPBUF) { }
  514.   public:
  515.     virtual int pbackfail(int c);
  516.     virtual int underflow();
  517.     virtual int overflow(int c = EOF);
  518. };
  519.  
  520. struct __file_fields {
  521.     short _fileno;
  522.     _G_size_t _blksize;
  523.     _G_fpos_t _offset;
  524. //    char* _save_gptr;  char* _save_egptr;
  525. };
  526.  
  527. class filebuf : public backupbuf {
  528.   protected:
  529.     struct __file_fields _fb;
  530.     void init();
  531.   public:
  532.     static const int openprot; // Non-ANSI AT&T-ism:  Default open protection.
  533.     filebuf();
  534.     filebuf(int fd);
  535.     filebuf(int fd, char* p, _G_size_t len);
  536.     ~filebuf();
  537.     filebuf* attach(int fd);
  538.     filebuf* open(const char *filename, const char *mode);
  539.     filebuf* open(const char *filename, ios::openmode mode, int prot = 0664);
  540.     virtual int underflow();
  541.     virtual int overflow(int c = EOF);
  542.     int is_open() const { return _fb._fileno >= 0; }
  543.     int fd() const { return is_open() ? _fb._fileno : EOF; }
  544.     filebuf* close();
  545.     virtual int doallocate();
  546.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  547.     virtual streambuf* setbuf(char* p, _G_size_t len);
  548.     _G_size_t xsputn(const char* s, _G_size_t n);
  549.     _G_size_t xsgetn(char* s, _G_size_t n);
  550.     virtual int sync();
  551.   protected: // See documentation in filebuf.C.
  552. //    virtual int pbackfail(int c);
  553.     int is_reading() { return eback() != egptr(); }
  554.     char* cur_ptr() { return is_reading() ?  gptr() : pptr(); }
  555.     /* System's idea of pointer */
  556.     char* file_ptr() { return eGptr(); }
  557.     int do_write(const char *data, _G_size_t to_do);
  558.     int do_flush() { return do_write(_pbase, _pptr-_pbase); }
  559.     // Low-level operations (Usually invoke system calls.)
  560.     virtual _G_ssize_t sys_read(char* buf, _G_size_t size);
  561.     virtual _G_fpos_t sys_seek(_G_fpos_t, _seek_dir);
  562.     virtual _G_ssize_t sys_write(const void*, _G_size_t n);
  563.     virtual int sys_stat(void*); // Actually, a (struct stat*)
  564.     virtual int sys_close();
  565. };
  566.  
  567. inline ios::ios(streambuf* sb /* = 0 */, ostream* tie /* = 0 */) {
  568.         _state = sb ? ios::goodbit : ios::badbit; _exceptions=0;
  569.         _strbuf=sb; _tie = tie; _width=0; _fill=' ';
  570.         _flags=ios::skipws|ios::dec; _precision=6; }
  571. inline ios::~ios() {
  572.     if (!(_flags & (unsigned int)ios::dont_close)) delete _strbuf; }
  573.  
  574. #endif /* _STREAMBUF_H */
  575.